#include <iostream>
#include <algorithm>

using namespace std;

const int N = 100010, INF = 0x3f3f3f3f;

int n;
int w[N], f[N][3];

int main() {
    cin >> n;
    
    for (int i = 1; i <= n; ++ i) scanf("%d", w + i);
    
    f[0][0] = -INF, f[0][1] = -INF;
    
    for (int i = 1; i <= n; ++ i) {
        f[i][0] = max(f[i - 1][0], f[i - 1][2] - w[i]);
        f[i][1] = max(f[i - 1][0] + w[i], f[i - 1][1]);
        f[i][2] = max(f[i - 1][1], f[i - 1][2]);
    }
    
    cout << max(f[n][1], f[n][2]) << endl;
    
    return 0;
}